package nancal.mp.db.mongo

import nbcp.base.extend.IsIn
import nbcp.base.extend.IsInItems
import nbcp.base.utils.StringUtil


enum class OpsWorkStatusEnum{
    waiting,
    working,
    cancel,
    done
}

enum class DeployExecutorEnum {
    Jenkins,
    Docker
}


enum class TableViewTypeEnum {
    Table,
    View
}

enum class ServiceNameStyleEnum {
    /**
     * 仅仅使用 appName
     */
    Default,

    /**
     * 使用 产品线编码做前缀
     */
    ProductLineCode,

    /**
     * 使用 语言编码做后缀
     */
    Language,

    /**
     * 使用 产品线编码做前缀,语言编码做后缀
     */
    ProductLineCodeLanguage;


    fun getServiceName(appName: String, productLineCode: String, language: JenkinsLanguageEnum): String {
        if (appName.isEmpty()) {
            throw IllegalArgumentException("appName 不能为空")
        }
        if (this == ServiceNameStyleEnum.Default) {
            return appName
        }

        if (this == ServiceNameStyleEnum.ProductLineCode) {

            var sects = StringUtil.getKebabCase(appName).split("-").toMutableList();
            if (sects.first() != productLineCode) {
                sects.add(0, productLineCode);
            }

            return sects.filter { it != "-" }.joinToString("-");
        }


        if (this == ServiceNameStyleEnum.Language) {
            var lang = language.toString().lowercase()
            var sects = StringUtil.getKebabCase(appName).split("-").toMutableList();
            if (sects.last() != lang) {
                sects.add(lang);
            }

            return sects.joinToString("-");
        }

        if (this == ServiceNameStyleEnum.ProductLineCodeLanguage) {
            var lang = language.toString().lowercase()
            var sects = StringUtil.getKebabCase(appName).split("-").toMutableList();

            if (sects.first() != productLineCode) {
                sects.add(0, productLineCode);
            }

            if (sects.last() != lang) {
                sects.add(lang);
            }

            return sects.filter { it != "-" }.joinToString("-");
        }

        throw RuntimeException("不识别的枚举类型： ${this}");
    }
}

enum class PackageToolEnum(val value: String) {
    Npm("npm"),
    Yarn("yarn")
}

enum class SnapshotVersionActionEnum {
    Ignore,
    Warn,
    Error
}

enum class CodeTemplateCoderTypeEnum {
    Text,
    Editor
}

enum class EditorLocationEnum {
    Before,
    After,
    ReplaceLine,
    ReplaceWord,
}

/**
 * Git服务器类型
 */
enum class GitServerTypeEnum {
    Gitea,
    Gitlab
}


enum class K8sYamlType {
    Deployment,
    Service
}

/**
 * Created by udi on 17-3-28.
 */
enum class UserSystemTypeEnum(val remark: String) {
    TenantUser("互联网用户"),
    TenantAdmin("企业用户"),
    Boss("管理用户")
}

enum class JenkinsJobStatusEnum(val remark: String) {
    None("未开始"),
    Created("已创建"),
    Prepare("准备中"),
    Working("工作中"),
    Expired("已过期"),
    Success("成功"),
    Failure("失败"),
    Canceled("取消");
}

enum class OpsDeployStageEnum(val remark: String) {
    PreBuild("构建前"),
    PostBuild("构建中")
}

/**
 *
 */
enum class ProductStatusEnum(val remark: String) {
    Online("在售"),
    Promotion("促销"),
    Offline("下架")
}

enum class ApproveStatusEnum(val remark: String) {
    Create("已创建"),
    Read("已读"),
    Agree("同意"),
    Reject("拒绝")
}

enum class ClientTypeEnum(val remark: String) {
    app("手机客户端"),
    wxApp("微信小程序"),
    h5("H5"),
    Web("Web")
}

//saas 平台系统枚举  devops云  制造云  研发云   管理云   数据云
enum class SassEnum(val remark: String) {
    None("无"),

    //五朵云
    DevOps("devops云"),
    Make("制造云"),
    Development("研发云"),
    DataLake("数据云"),
    Management("管理云")
}

//微服务库  业务域枚举
enum class DomainEnum(val remark: String) {
    Finance("财务域"),
    Person("人力域"),
    Contract("合同域"),
    Sale("销售域"),
    Design("设计域"),
    Research("研发域"),
    Plan("计划域"),
    SupplyChain("供应链域"),
    Storage("仓储域"),
    Make("制造域"),
    Quality("质量域"),
    Logistics("物流域"),
}

//中台系统枚举
enum class Platform(val remark: String) {
    Technology("技术中台"),
    Business("业务中台"),
    Data("数据中台"),
    App("应用"),
    Strings("文字配置"),
    Other("其他")
}

//规模
enum class PersonCountEnum(val remark: String) {
    Min("少于100人"),
    Little("101-500人"),
    More("501-1000人"),
    Max("超过1000人")
}

//行业
enum class IndustryEnum(val remark: String) {
    ChemicalProduct("化学制品"),
    Plastic("塑料制品"),
    Metal("金属制品"),
    ElectricalApparatus("电器及配件"),
    Food("农副食品"),
    ChemicalMaterials("化工原料"),
    Electricalmachinery("电气机械及器材"),
    Petroleum("石油"),
    Hospital("医药与医疗器械"),
    Other("其他")
}

//devops  子系统枚举
enum class SubSystemEnum(val remark: String) {
    microService("微服务库"),
    zentao("禅道"),
    confluence("文档管理"),
    gitea("源码管理"),
    sonarqube("代码检查"),
    jenkins("自动部署"),
    yapi("接口管理"),
    kuboard("云容器管理"),
    harbor("镜像管理"),
    skywalking("调用链管理"),
    grafana("系统监控"),
    nacos("注册配置中心"),
    mendix("mendix"),
    datalake("数据湖")
}

/**
 * 项目状态枚举
 */
enum class ProjectStatusEnum(val remark: String) {
    None("未开始"),
    Doing("进行中"),
    Over("已结束"),
}


enum class FormFieldTypeEnum(val remark: String) {
    Text("文本"),
    Number("数值"),
    Radio("单选"),
    Check("多选"),
    Boolean("布尔"),
    File("文件") //可多个
}

//统计类型   day /  month
enum class StatisticsEnum(val remark: String) {
    Day(remark = "天"),
    Month(remark = "月")
}

enum class PipelineTemplateEnum(val remark: String) {
    K8s("容器"),
    Native("原生运行"),
    Docker("Docker")
}

/**
 * 必须是全小写。  spring.profiles.active 的一部分。
 */
enum class MicroServiceDeployEnvEnum(val remark: String) {
    boot("boot"),
    k8s("容器"),
    nacos("nacos"),
    consul("consul")
}

enum class SystemEnvEnum(val remark: String) {
    dev("开发"),
    test("测试"),
    main("生产")
}

enum class JenkinsLanguageEnum {
    /**
     * Java系列都算,像 Kotlin等
     */
    Java,

    /**
     * npm打包的都算，包括 React,angular
     */
    Vue,
    Node,
    Nuxt,
    Python,
    Php,
    Normal;

    companion object {
        fun getServerLanguage(): Array<JenkinsLanguageEnum> {
            return arrayOf(Java, Node, Nuxt, Python, Php)
        }

        /**
         * 需要Nginx镜像的语言
         */
        fun getNeedNginxImageLanguage(): Array<JenkinsLanguageEnum> {
            return arrayOf(Vue)
        }

        /**
         * 需要最外层 Nginx 转发的语言
         */
        fun getNginxVpathStyle(): Array<JenkinsLanguageEnum> {
            return arrayOf(Vue, Nuxt)
        }
    }

    /**
     * 需要Nginx镜像的语言
     */
    fun isNeedNginx(): Boolean {
        return getNeedNginxImageLanguage().contains(this);
    }

    /**
     * 需要 yarn start 启动的语言
     */
    fun hasPackageJson(): Boolean {
        return this.IsInItems(Nuxt, Node, Vue)
    }

}

enum class JenkinsGitBranchEnum(val remark: String) {
    dev("开发版"),
    test("测试版"),
    demo("演示版"),
    pre("预发版"),
    main("正式版");
}


enum class GitFileActionEnum(val remark: String) {
    add("添加"),
    delete("删除文件"),
    modify("修改文件");
}

enum class BaseServiceEnum {
    mariadb,
    mongo,
    redis,
    rabbitmq,
    es,
    influxdb,
    sentinel,
    minio
}